package com.demo;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.yq.timer.TimerBean;
import org.yq.timer.TimerCollection;

/**
 * Servlet implementation class TestServlet
 */
@WebServlet("/TestServlet")
public class TestServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public TestServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String param = request.getParameter("param");
		try {
			
			if("add".equals(param)){
				TimerCollection.startTimer(new TimerBean("timerid2", "org.yq.timer.TestTimerTask", 2000, 1000));
			}else if("stop".equals(param)){
				TimerCollection.stopTimer("timerid");
			}else if("stop2".equals(param)){
				TimerCollection.stopTimer("timerid2");
			}else if("exec".equals(param)){
				TimerCollection.execute(new TimerBean("timerid2", "org.yq.timer.TestTimerTask", 2000, 1000));
			}else if("list".equals(param)){
				response.getWriter().write(TimerCollection.getTimers().toString());
			}else{
				SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				String str1 = "2015-6-4 19:12:00";
				Date n1 = format.parse(str1);
				TimerCollection.startTimer(new TimerBean("timerid", "org.yq.timer.TestTimerTask", n1, 3000));
			} 
			
			
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("doGet:"+param);
		response.getWriter().write("hello world !");
		 
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
